package com.aigou.admin.entity;

import com.alibaba.fastjson2.JSON;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 返回给前端的统一格式
 */
public class ResponseEntity {

    //描述信息
    private String msg;
    //绑定数据
    private Object data;

    public ResponseEntity(String msg, Object data) {
        this.msg = msg;
        this.data = data;
    }

    public ResponseEntity() {
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseEntity{" +
                "msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
    public static void ok(HttpServletResponse resp, Object data) throws IOException {
        resp.getWriter().write(JSON.toJSONString(new ResponseEntity("OK",data)));
    }
}
